<template>
    <div class="trid">
        <tr>
            <td><input type="checkbox" :checked="bug.checked" @click="clkChecked(bug.id)"></td>
            <td>
                <span id="tdM" v-show="!bug.editState" @click="enterEdit(bug)">
                    {{bug.info}}
                </span>
                <input id="tdM" ref="inputfocus" type="text" :value="bug.info" v-show="bug.editState"
                    @blur="updateInput(bug,$event)">
            </td>
            <td><button class="btn-del" @click="del(bug.id)">删除</button></td>
        </tr>
    </div>
</template>

<script>
    export default {
        name: 'HelloWorldBufItem',
        props: ['bug', 'clkCheckedCallBack', 'updateInputCallBack','delText'],
        data() {
            return {

            };
        },
        methods: {
            clkChecked(e) {
                this.clkCheckedCallBack(e)
            },
            enterEdit(bug) {
                if (bug.hasOwnProperty('editState')) {
                    bug.editState = true
                } else {
                    this.$set(bug, 'editState', true)
                }
                this.$nextTick(function () {
                    this.$refs.inputfocus.focus()
                });
            },
            updateInput(bug, e) {
                if (bug.hasOwnProperty('editState')) {
                    bug.editState = false
                } else {
                    this.$set(bug, 'editState', false)
                }
                let val = e.target.value
                let data = { id: bug.id, val: val }
                this.updateInputCallBack(data)
            },
            del(e) {
                this.delText(e);
            },
        },
    };
</script>

<style  scoped>
    td {
        width: 170px;
        text-align: center;
        background-color: springgreen;
        /* text-align: center; */
    }
</style>